{% extends "base.html" %}

{% block content %}
<div class="container mt-5">
    <h2 class="mb-4">用户管理</h2>
    <div class="table-responsive">
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>用户名</th>
                    <th>邮箱</th>
                    <th>注册时间</th>
                    <th>最后登录</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for user in users %}
                <tr>
                    <td>{{ user.id }}</td>
                    <td>{{ user.username }}</td>
                    <td>{{ user.email }}</td>
                    <td>{{ user.created_at.strftime('%Y-%m-%d') }}</td>
                    <td>{{ user.last_login.strftime('%Y-%m-%d %H:%M') if user.last_login else '从未登录' }}</td>
                    <td>
                        {% if user.is_active %}
                        <span class="badge bg-success">活跃</span>
                        {% else %}
                        <span class="badge bg-danger">禁用</span>
                        {% endif %}
                    </td>
                    <td>
                        {% if user.id != current_user.id %}
                        <form action="{{ url_for('admin.delete_user', id=user.id) }}" method="POST" class="d-inline">
                            <button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('确定要删除此用户吗？')">删除</button>
                        </form>
                        {% endif %}
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
    
    {% if pagination and pagination.pages > 1 %}
    <nav aria-label="Page navigation" class="mt-4">
        <ul class="pagination justify-content-center">
            {% for page in pagination.iter_pages() %}
                {% if page %}
                    <li class="page-item {% if page == pagination.page %}active{% endif %}">
                        <a class="page-link" href="{{ url_for('admin.users', page=page) }}">{{ page }}</a>
                    </li>
                {% else %}
                    <li class="page-item disabled">
                        <span class="page-link">...</span>
                    </li>
                {% endif %}
            {% endfor %}
        </ul>
    </nav>
    {% endif %}
</div>
{% endblock %} 